package com.mlh.binarytree;

/**
 * @author 缪林辉
 * @date 2024/3/26 11:35
 * @DESCRIPTION
 */
// 给你一棵二叉树的根节点 root ，翻转这棵二叉树，并返回其根节点。
public class 翻转二叉树 {
    public TreeNode method1(TreeNode root) {
        if(root==null){return root;}
        method1(root.left);
        method1(root.right);
        TreeNode temp=root.left;
        root.left=root.right;
        root.right=temp;
        return root;
    }

    public TreeNode practice(TreeNode root) {
       return recursionPractice(root);
    }

    public TreeNode recursionPractice(TreeNode root){
        if(root==null){
            return null;
        }
        TreeNode left = recursionPractice(root.left);
        TreeNode right = recursionPractice(root.right);
        root.right=left;
        root.left=right;
        return root;
    }

    public TreeNode practice2(TreeNode root) {
       if(root==null){
           return null;
       }
        return recursionPractice2(root);
    }

    public TreeNode recursionPractice2(TreeNode node){
      if(node==null){
          return null;
      }
      TreeNode left = recursionPractice2(node.left);
      TreeNode right = recursionPractice2(node.right);
      node.left=right;
      node.right=left;
      return node;
    }
}
